package com.lagou.servlet;

import com.lagou.service.UserService;
import com.lagou.service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet(name = "deleteStudentServlet",urlPatterns = "/deleteStudentServlet")
public class deleteStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 拿到id
        Integer id = Integer.parseInt(request.getParameter("code"));
        UserService userService = new UserServiceImpl();
        boolean b = userService.deleteStudent(id);
        if (b==true){
            request.getRequestDispatcher("/showAllUserServlet").forward(request,response);
        }else{
            System.out.println("删除失败!");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
